<template>
	<view class="app-pages">
		<view class="cell">
			<u-cell :border="false">
				<view class="mp_title" slot="title">{{needData.productName || ''}} ×{{needData.productNum || ''}}</view>
				<view class="" slot="label">
					<view class="label">
						<view class="label-item">
							<view class="label-item-name">使用日期</view>
							<view class="label-item-value">{{needData.date}}</view>
						</view>
						<view class="label-item">
							<view class="label-item-name">入塔时间</view>
							<view class="label-item-value">08:30-21:30</view>
						</view>
						<view class="label-item">
							<view class="label-item-name">地址</view>
							<view class="label-item-value">中央电视塔一层入塔检票处验证入园</view>
						</view>
					</view>
				</view>
			</u-cell>
		</view>
		<view class="cell qr">
			<view class="title">凭【二维码】直接入园</view>
			<view class="title-tips">{{codeUrl || ''}}</view>
			<canvas style="width: 300rpx;height: 300rpx;" canvas-id="logoQRCode" />
			<view class="footer">
				<text></text>
				<!-- <text style="margin-left: 50rpx;">1101**********121</text> -->
			</view>
		</view>
		<blockquote v-if="peopleData">
			<view class="cell" v-if="!peopleData.ticketDisabled">
				<button style="background-color: #ffffff;" @click="handleQuit(needData)">退票</button>
			</view>			
		</blockquote>
	</view>
</template>
<script>
	import drawQrcode from '@/utils/weapp.qrcode.min.js';
	import {
		getDetailListByOrderNumMobile,
		refundOfOrder
	} from "@/http";
	export default {
		data() {
			return {
				selectDate: '',
				peopleData: null,
				options: {},
				needData: '',
				codeUrl: ''
			}
		},
		mounted() {},
		methods: {
			async handleQuit(options) { //退票
				try {
					let options = this.peopleData;
					uni.showLoading({
						title: "正在退票..."
					});
					let res1 = await getDetailListByOrderNumMobile({
						orderNum: options.orderNum,
						pageNum: 1,
						pageSize: 10
					});
					let res2 = await refundOfOrder({
						eCodeList: [res1.data.rows[0].eCode],
						orderNum: options.orderId,
						userCard: options.f1,
						userName: options.userName,
						userPhone: options.userPhone
					});
					uni.showToast({
						title: "退票成功",
						icon: "success"
					});
					setTimeout(() => {
						uni.hideLoading();
						uni.navigateBack();
					}, 2000)
				} catch (err) {
					uni.hideLoading();
				};
			},
		},
		onLoad(o) {
			uni.showLoading({
				title: '二维码生成中...'
			});
			if (uni.getStorageSync('people_data')) this.peopleData = uni.getStorageSync('people_data') || {};
			console.log("查看传过来的参数：",this.peopleData)
			this.codeUrl = uni.getStorageSync('code_url');
			uni.setStorageSync('code_url','');
			uni.setStorageSync('people_data', ''); //清空
			if(o.needData) this.needData = JSON.parse(o.needData);
			drawQrcode({
				width: 150,
				height: 150,
				x: 0,
				y: 0,
				canvasId: 'logoQRCode',
				typeNumber: 13, //最大27
				text: this.codeUrl,
				background: '#FFFFFF', //二维码背景颜色，默认值白色
				foreground: '#000000', //二维码前景色，默认值黑色
				/*image:{ //二维码中间放图片
				  imageResource: '../../images/d.png',
				  dx: 70,
				  dy: 70,
				  dWidth: 60,
				  dHeight: 60
				},*/
				// correctLevel: 3, //非必须，二维码纠错级别，默认值为高级，取值：{ L: 1, M: 0, Q: 3, H: 2 }
				callback(e) {
					uni.hideLoading();
					console.log('微信小程序二维码: ', e)
				}
			});
		}
	}
</script>
<style>
	page {
		background-color: #F6F6F6 !important;
	}
</style>
<style lang="scss" scoped>
	.app-pages {
		// background-color: #F6F6F6;
		// overflow: auto;
		// min-height: 100vh;
	}

	.cell {
		margin-top: 50rpx;
		background-color: #fff;

		// box-shadow: 0 0 4rpx #ccc;
		.mp_title {
			font-size: 36rpx;
			font-weight: 600;
		}

		.label {
			padding: 30rpx 0 0 24rpx;
			font-size: 26rpx;

			.label-item {
				display: flex;
				margin-bottom: 30rpx;

				&+.label-item {
					margin-top: 15rpx;
				}

				.label-item-name {
					width: 160rpx;
				}

				.label-item-value {
					color: #F59A23;
				}
			}
		}
	}

	.qr {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;

		.title {
			padding-top: 30rpx;
			// padding-bottom: 50rpx;
		}
		.title-tips{
			margin:20rpx 0;
			font-size: 26rpx;
		}

		.footer {
			padding-top: 50rpx;
			padding-bottom: 30rpx;
		}
	}
</style>
